<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加文章</title>
    <link rel="stylesheet" href="/admin/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">所属分类</label>
                    <div class="layui-input-block">
                        <select name="cate_id" lay-verify="">
                            <option value="0">清选择分类</option>
                            {% if cate_list %}
                                {% for cate_item in cate_list %}
                                    <option value="{{ cate_item.id }}">{{ cate_item.name }}</option>
                                {% endfor %}
                            {% endif %}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" lay-verify="title" 
                            autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="1" title="启用">
                        <input type="radio" name="status" value="0" title="禁用" checked>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="art-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

<script src="/admin/component/layui/layui.js"></script>
<script src="/admin/component/pear/pear.js"></script>
<script>
layui.use(['form','jquery'],function(){
    let form = layui.form;
    let $ = layui.jquery;

    form.on('submit(art-save)', function(data){

        $.ajax({
            url: "/admin/art/create",
            data: data.field,
            dataType:'json',
            type:'post',
            success:function(result) {
                if (result.code == 0) {
                    layer.msg(result.message, {icon:1,time:1000}, function() {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.layui.table.reload("art-table");
                    });
                } else {
                    layer.msg(result.message, {icon:2,time:1000});
                }
            }
        })
        return false;
    });
})
</script>
<script>
</script>
</body>
</html>